package eclipse.lib.scripting;

import eclipse.Constants;
/**
 * The Decoder Class is an abstract class that can be added to support comCode in another class or application.
 */
public abstract class ByteDecoder
{
	/** 
	 * Starts the Decoding process
	 * @param byteArray ByteArray containing the script.
	 */
	public void decode(ByteArray byteArray)
	{
		decode(byteArray.toArray());
	}
	/**
	 * Starts the Decoding process
	 * @param byteArray Array of bytes containing the script
	 */
	public void decode(byte[] byteArray)
	{
		byte[] comCode = byteArray;
		byte[] command;
		int offset_END;
		int offset_START;		
		for(int a = 0; a < comCode.length; a++)
		{
			if(comCode[a] == Constants.com_START)
			{					
				offset_START = a + 1;
				for(int b = offset_START; b < comCode.length; b++)				
				{
					if(comCode[b] == Constants.com_END)					
					{
						offset_END = b;						
						command = ByteInterpreter.getSubByteArray(comCode, offset_START, offset_END);
						parser(new ByteArray(command));
						break;
					}
				}
			}
		}
	}
	public abstract void parser(ByteArray command);
}
